package com.tengju.support.domain.model.robot;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
@Slf4j
public class ReqParamFactory {

    public static ReqParam create(String text, String employeeId) {

        if (StringUtils.isEmpty(text)) {
            return null;
        }

        String[] textSplit = text.split("[:：]", 2);
        if (textSplit.length != 2 || StringUtils.isEmpty(textSplit[0]) || StringUtils.isEmpty(textSplit[1])) {
            return null;
        }
        ParamType paramType = ParamType.fromVal(textSplit[0].trim());
        if (paramType == null) {
            return null;
        }
        String[] param = textSplit[1].split("[,，]");
        return new ReqParam(paramType, param, employeeId);

    }

}
